cmake_minimum_required(VERSION 3.8)
project(mult_lidar)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()


# 查找依赖
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(pcl_conversions REQUIRED)
find_package(PCL REQUIRED)
find_package(visualization_msgs REQUIRED)
find_package(PCL REQUIRED COMPONENTS common filters)
find_package(pcl_ros REQUIRED)
find_package(tf2 REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(Sophus REQUIRED)
find_package(Ceres REQUIRED)
find_package(tf2_geometry_msgs REQUIRED)
find_package(OpenCV REQUIRED
  COMPONENTS
    core
    imgproc
)


include_directories(
  include
  ${Boost_INCLUDE_DIRS}
  ${PCL_LIBRARY_DIRS}
  ${EIGEN3_INCLUDE_DIR}
  ${OpenCV_INCLUDE_DIRS}
  ${PCL_INCLUDE_DIRS}
)


add_library(mult_lidar_lib
  src/voxel_voting_filter.cpp
  src/pointcloud_processor.cpp
  src/barrel_detector.cpp
  src/manhole_detector.cpp
  src/detection_manager.cpp
  src/neutron_detector.cpp
)

# 链接库
ament_target_dependencies(mult_lidar_lib
  rclcpp
  std_msgs
  sensor_msgs
  geometry_msgs
  pcl_conversions
  tf2
  tf2_ros
  visualization_msgs
  pcl_conversions
  tf2_geometry_msgs
)

#库文件链接
target_link_libraries(mult_lidar_lib
    Eigen3::Eigen 
    Sophus::Sophus 
    ceres 
      ${PCL_LIBRARIES}
      ${Sophus_LIBRARIES}
      ${sensor_msgs_LIBRARIES}
      ${geometry_msgs_LIBRARIES}
      ${pcl_conversions_LIBRARIES}
      ${PCL_LIBRARIES}
      ${OpenCV_LIBRARIES} #opencv
)


target_compile_definitions(mult_lidar_lib PUBLIC PCL_NO_PRECOMPILE)


# 添加可执行文件
#add_executable(mult_lidar src/split_cloud.cpp src/mult_lidar.cpp)
add_executable(mult_lidar_node src/mult_lidar_node.cpp)
ament_target_dependencies(mult_lidar_node
  rclcpp
  sensor_msgs
  geometry_msgs
  std_msgs
  pcl_conversions
  tf2_ros
)
target_link_libraries(mult_lidar_node
  mult_lidar_lib
  ${PCL_LIBRARIES}
)

target_compile_definitions(mult_lidar_node PUBLIC PCL_NO_PRECOMPILE)


#头文件包含
#target_include_directories(mult_lidar PUBLIC

  #${Sophus_INCLUDE_DIRS}
  
#)


# 安装规则
install(TARGETS
  mult_lidar_lib
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib
  RUNTIME DESTINATION bin
)

install(TARGETS
  mult_lidar_node
  DESTINATION lib/${PROJECT_NAME}
)

install(DIRECTORY include/
  DESTINATION include/
)

install(DIRECTORY
  config
  launch
  DESTINATION share/${PROJECT_NAME}/
)



# 导出包
ament_export_include_directories(include)
ament_export_libraries(mult_lidar_lib)
ament_export_dependencies(
  rclcpp 
  sensor_msgs 
  geometry_msgs 
  std_msgs 
  PCL 
  pcl_conversions 
  tf2_ros
)
ament_package()